package com.assignment.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.text.DefaultEditorKit;

public class CustomJMenuBar extends JMenuBar  implements ActionListener {

	JMenu fileMenu,editMenu,newMenu,helpMenu;
	JMenuItem exitItem,cutItem,copyItem,pasteItem,aboutItem,helpItem,itemItem,supplierItem;
	SearchScreen frame;
	
	public CustomJMenuBar(SearchScreen frame) {
		this.frame=frame;
		
		fileMenu = new JMenu("File");
		editMenu = new JMenu("Edit");
		newMenu = new JMenu("New");
		helpMenu = new JMenu("Help");
		
		add(fileMenu);
		add(editMenu);
		add(newMenu);
		add(helpMenu);
		
		
		exitItem = new JMenuItem("Exit");
		exitItem.addActionListener(this);
		fileMenu.add(exitItem);
		
		cutItem = new JMenuItem(new DefaultEditorKit.CutAction());
		editMenu.add(cutItem);
		copyItem = new JMenuItem(new DefaultEditorKit.CopyAction());
		editMenu.add(copyItem);
		pasteItem = new JMenuItem(new DefaultEditorKit.PasteAction());
		editMenu.add(pasteItem);
		
		
		itemItem = new JMenuItem("New Item");
		newMenu.add(itemItem);
		itemItem.addActionListener(this);
		supplierItem = new JMenuItem("New Supplier");
		newMenu.add(supplierItem);
		supplierItem.addActionListener(this);
		
		helpItem = new JMenuItem("View Tutorial");
		helpItem.addActionListener(this);
		helpMenu.add(helpItem);
		
		aboutItem = new JMenuItem("About");
		aboutItem.addActionListener(this);
		helpMenu.add(aboutItem);
		
		
	}
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		
		if (e.getSource()==exitItem) {
			int reply = JOptionPane.showConfirmDialog(null, "Are you sure you want to close?", "Close?",  JOptionPane.YES_NO_OPTION);
			if (reply == JOptionPane.YES_OPTION)
			{
			   System.exit(0);
			}
		}
		else if (e.getSource()==itemItem)
			frame.btnNewFireplace.getActionListeners()[0].actionPerformed(e);
		else if (e.getSource()==supplierItem)
			frame.btnNewSupplier.getActionListeners()[0].actionPerformed(e);
		else if (e.getSource()==aboutItem)
			new AboutScreen();
		else if (e.getSource()==helpItem)
			new TutorialScreen();
	}
}
